package com.example.demo.service.Impl;

import com.example.demo.dao.IBhmana;
import com.example.demo.model.Bhmana;
import com.example.demo.service.IBhmanaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

;

/**
 * @author Administrator 张少婷
 */

@Service
public class BhmanaServiceImpl implements IBhmanaService {

    @Autowired
    private IBhmana bhmanaMapper;
    @Override
    public int insertBhmana(Bhmana bhmana){
        int bhmanaValue=0;

        Bhmana bhmana1=new Bhmana();
        bhmana1.setLbid(bhmana.getLbid());
        List<Bhmana> getB=bhmanaMapper.getAllBhmana(bhmana1);
        if(getB.size()>0){
            bhmanaValue=-1;

        }else{
            bhmanaValue=bhmanaMapper.insertBhmana(bhmana);
        }

        return bhmanaValue;
    }

    @Override
    public List<Bhmana> getAllBhmana(Bhmana bhmana) {


        return bhmanaMapper.getAllBhmana(bhmana);
    }

    @Override
    public int updateBhmana(Bhmana bhmana) {
        int bhmanaValues=0;
        if(bhmana.getLbid()!=0){
            bhmanaValues=bhmanaMapper.updateBhmana(bhmana);
        }
        return bhmanaValues;
    }

    @Override
    public int deleteBhmana(Bhmana bhmana) {
        int bhmanaValues=0;
        if(bhmana.getLbid()!=0)
        {
            //主键是否与其他表有关联

            bhmanaValues=bhmanaMapper.deleteBhmana(bhmana);
        }
        return bhmanaValues;
    }

    @Override
    public Bhmana getBhmana(Bhmana bhmana) {
        Bhmana bhmana1=new Bhmana();
        if(bhmana.getLbid()!=0){
            bhmana1=bhmanaMapper.getBhmana(bhmana);
        }
        return bhmana1;
    }

}
